home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / zm16src.lzh / RZ.C < prev    next >
C/C++ Source or Header  |  1988-05-19  |  29KB  |  1,449 lines

  1. /*
  2.  *                ACKNOWLEDGEMENTS
  3.  *
  4.  *    ZMDM was derived from rz/sz for Unix  posted by 
  5.  *    Chuck Forsberg (...!tektronix!reed!omen!caf ). We
  6.  *    thank him for his excellent code, and for giving
  7.  *    us permission to use and distribute his code and
  8.  *    documentation.
  9.  *
  10.  *    Atari St version by:
  11.  *        Jwahar Bammi
  12.  *            usenet: mandrill!bammi@{decvax,sun}.UUCP
  13.  *            csnet:  bammi@mandrill.ces.CWRU.edu
  14.  *            arpa:   bammi@mandrill.ces.CWRU.edu
  15.  *            CompuServe: 71515,155
  16.  */
  17.  
  18. #include "config.h"
  19. #define RVERSION "rz 1.14 01-15-87"
  20. #define RSTVERSION "rz 1.01 03-07-87"
  21. #define OS    "Unix V7/BSD"
  22.  
  23. /* #define RDEBUG */            /* a lot of debugging garb */
  24.  
  25. /*
  26.  *    ATARI ST series implementation notes:
  27.  *
  28.  *        - the following command line options were removed as they
  29.  *          were either  not applicable to the ST environment or
  30.  *          were not deemed reasonable (by me - ofcourse).
  31.  *            1    Not Applicable here as we have a seperate
  32.  *                serial port.
  33.  *            7    In this day and age? Forget it, get another m/c.
  34.  *            a/b    Ascii/Binary - the receive mode (if not
  35.  *                over-ridden by the sender) is automatically
  36.  *                selected depending on the extention given
  37.  *                in the incoming file name. This idea was
  38.  *                present in earlier rz/sz, i wonder why such
  39.  *                a convenient feature was dropped (Chuck ??).
  40.  *                This feature is relevant to ZMODEM only in rz,
  41.  *                as the sender determines the file mode in
  42.  *                XMODEM/YMODEM transfers.
  43.  *                B    Note that `B' has a special meaning.
  44.  *                Specifying -B will force override to
  45.  *                binary mode for each incoming file. Useful
  46.  *                 when doing St-to-St transfers.
  47.  *            D    There is no /dev/null on the ST's
  48.  *            u    not applicable to TOS. Upper and lower
  49.  *                case file names are the same. All the
  50.  *                applicable routines like uncap() and
  51.  *                IsAnyLower() were zapped.
  52.  *
  53.  *        - The    [-][v]rzCOMMAND style of invocation was dropped
  54.  *          as there is no good way to do pipes without the 
  55.  *          microRtx kernal. All references to Pipe and popen()
  56.  *          were zapped.
  57.  *        - Verbose is always set to 2 by automatically, as we know that
  58.  *          stdout != stderr. This can be overridden
  59.  *          by specifying -q to ensure that Verbose = 0
  60.  *        - The idea of a PUBDIR and Restricted paths in the origonal
  61.  *          code  was dropped totally as it is not applicable
  62.  *          to the single owner ST environment. 1 man 1 machine.
  63.  *        - CRCTABLE is default always, hey we have plenty of memory!.
  64.  *        - LOGFILE renamed to 'rzlog/szlog' as we don't always have
  65.  *          a meaningful environment to pick up TMPDIR from (like when
  66.  *          running from the desktop).
  67.  *            - When a subdirectory in an incoming path name is not
  68.  *          present it is created.
  69.  *        - The file mode transmitted is 0S00 where S is derived from
  70.  *          the Read/Write attribute of the file on the ST
  71.  *        - When a file mode is received, only the owner bits are
  72.  *          are checked. If it was read only (r--) on the Unix sytem
  73.  *          then it is given read only attribute on the ST, read-write
  74.  *          otherwise.
  75.  *        - Of course all the I/O was completely redone on the ST.
  76.  *        - You will find two versions of VARARGS routines like log,
  77.  *          one that takes int args, and the other that takes long
  78.  *          (address) args, since sizeof(int) != sizeof(long)
  79.  *          and sizeof(int) != sizeof(pointer) on the ST.
  80.  *
  81.  *    ST v1.01
  82.  *     added support for 32 bit CRC's for Zmodem ++jrb
  83.  *
  84.  *    ST v1.2
  85.  *     added -B ++jrb
  86.  *     added all the recursive stuff
  87.  *     added remote
  88.  */
  89.         
  90. /*% cc -DNFGVMIN -DCRCTABLE -K -O % -o rz; size rz
  91.  *
  92.  * rz.c By Chuck Forsberg
  93.  *
  94.  *    cc -O rz.c -o rz        USG (3.0) Unix
  95.  *     cc -O -DV7  rz.c -o rz        Unix V7, BSD 2.8 - 4.3
  96.  *
  97.  *    ln rz rb            For either system
  98.  *
  99.  *    ln rz /usr/bin/rzrmail        For remote mail.  Make this the
  100.  *                    login shell. rzrmail then calls
  101.  *                    rmail(1) to deliver mail.
  102.  *
  103.  *        define CRCTABLE to use table driven CRC
  104.  *
  105.  *  Unix is a trademark of Western Electric Company
  106.  *
  107.  * A program for Unix to receive files and commands from computers running
  108.  *  Professional-YAM, PowerCom, YAM, IMP, or programs supporting XMODEM.
  109.  *  rz uses Unix buffered input to reduce wasted CPU time.
  110.  *
  111.  * Iff the program is invoked by rzCOMMAND, output is piped to 
  112.  * "COMMAND filename"
  113.  *
  114.  *  Some systems (Venix, Coherent, Regulus) may not support tty raw mode
  115.  *  read(2) the same way as Unix. ONEREAD must be defined to force one
  116.  *  character reads for these systems. Added 7-01-84 CAF
  117.  *
  118.  *  Alarm signal handling changed to work with 4.2 BSD 7-15-84 CAF 
  119.  *
  120.  *  NFGVMIN Added 1-13-85 CAF for PC-AT Xenix systems where c_cc[VMIN]
  121.  *  doesn't seem to work (even though it compiles without error!).
  122.  *
  123.  *  USG UNIX (3.0) ioctl conventions courtesy  Jeff Martin
  124.  */
  125.  
  126.  
  127. #include "zmdm.h"
  128. #include "common.h"
  129. #include "zmodem.h"
  130.  
  131. static unsigned long SaveIntr;
  132.  
  133. #ifndef Vsync             /* Atari forgot these in osbind.h */
  134. #define Vsync()    xbios(37)
  135. #endif
  136.  
  137. #ifndef Supexec
  138.         /* Some versions of osbind don't define Supexec */
  139. #define Supexec(X) xbios(38,X)
  140. #endif
  141.  
  142. #if (MWC || MANX)
  143. extern FILE  *fopen();
  144. #else
  145. extern FILE  *fopen(), *fopenb();
  146. #endif
  147.  
  148. #ifndef STANDALONE
  149. #define RETURN return
  150. #else
  151. int bibis() {} /* dummy */
  152. #endif 
  153.  
  154. static long start_time;
  155.  
  156. /* called by simulated signal interrupt or terminate to clean things up */
  157. bibi(n)
  158. int n;
  159. {
  160.  
  161.     if (Zmodem)
  162.         zmputs(Attn);
  163.     canit(); mode(0);
  164.     fprintf(STDERR, "\r\nrz: caught signal %d; exiting", n);
  165.     if (fout != -1)
  166.     {
  167.         if (stfclose(fout) != 0)
  168.         {
  169.             fprintf(STDERR, "\r\nfile close ERROR\n");
  170.         }
  171.         fout = (-1);
  172.  
  173.     }
  174.  
  175. #ifdef RDEBUG
  176.     if (logf != (FILE *)NULL)
  177.         fclose(logf);
  178. #endif
  179.     aexit(128+n);
  180. }
  181.  
  182. #ifdef STANDALONE
  183. main(argc, argv)
  184. #else
  185. dorz(argc, argv)
  186. #endif /* STANDALONE */
  187. int argc;
  188. char **argv;
  189. {
  190.     register char *cp;
  191.     register int npats;
  192.     char **patts;
  193.     int exitcode;
  194.  
  195. #ifdef STANDALONE
  196. #if (MWC || MANX)
  197.     extern char *lmalloc();
  198. #endif
  199.  
  200.     /* Set up Dta */
  201.     Fsetdta(&statbuf);
  202.  
  203.     /* Get screen rez */
  204.     rez = Getrez();
  205.     drv_map = Drvmap();
  206.  
  207. #if (MWC || MANX)
  208. #ifndef DYNABUF
  209.     if((bufr = (unsigned char *)lmalloc((unsigned long)BBUFSIZ))
  210.                      == (unsigned char *)NULL)
  211. #else
  212.     if((bufr = dalloc()) == (unsigned char *)NULL)
  213. #endif /* DYNABUF */
  214.     {
  215. #ifdef REMOTE
  216.         Bauxws("Sorry, could not allocate enough memory\r\n");
  217. #else
  218.         Bconws("Sorry, could not allocate enough memory\r\n");
  219. #endif
  220.  
  221.         Pterm(4);
  222.     }
  223. #else /* MWC || MANX */
  224. #ifdef DYNABUF
  225.     if((bufr = dalloc()) == (unsigned char *)NULL)
  226.     {
  227. #ifdef REMOTE
  228.         Bauxws("Sorry, could not allocate enough memory\r\n");
  229. #else
  230.         Bconws("Sorry, could not allocate enough memory\r\n");
  231. #endif
  232.         Pterm(5);
  233.     }
  234. #endif /* DYNABUF */
  235. #endif /* MWC || MANX */
  236.  
  237. #ifndef REMOTE
  238.     STDERR = stderr;
  239. #else
  240. #ifndef DLIBS
  241.     if((STDERR = fopen("aux:", "rw")) == (FILE *)NULL)
  242.     {
  243.         Bauxws("Could not Open Aux Stream for Stderr\r\n");
  244.         finish();
  245.     }
  246.     setbuf(STDERR, (char *)NULL);
  247. #else
  248.     STDERR = stdaux;
  249. #endif /* DLIBS */
  250.     
  251. #endif /* REMOTE */
  252.  
  253.     {
  254.         int speed;
  255.         speed = getbaud();
  256.         Baudrate = BAUD_RATE(speed);
  257.         SetIoBuf();
  258.         Rsconf(speed, 0,-1,-1,-1,-1);
  259.         Vsync(); Vsync();
  260.     }
  261.  
  262. #endif /* STANDALONE */
  263.  
  264.     SendType = 0;
  265.     Rxtimeout = 100;
  266.     exitcode = 0;
  267.  
  268.     initz();
  269.  
  270. #ifndef STANDALONE
  271.     chkinvok(argv[0]);     /* if called as  'rb' set flag */
  272. #else
  273.     Progname = "rz";
  274. #endif
  275.  
  276.     npats = 0;
  277.     SaveIntr = Setexc(0x0102, -1L);
  278.     BusErr   = Setexc(2, -1L);
  279.     AddrErr  = Setexc(3, -1L);
  280.     vdebug = 0;
  281.  
  282.     while (--argc)
  283.     {
  284.         cp = *++argv;
  285.         if (*cp == '-')
  286.         {
  287.             while( *++cp)
  288.             {
  289.                 switch(*cp)
  290.                 {
  291.                 case '+':
  292.                     Lzmanag = ZMAPND; break;
  293.                 case 'B':
  294.                     ForceBinary=TRUE; break;
  295.                 case 'c':
  296.                     Crcflg=TRUE; break;
  297.                 case 'p':
  298.                     Lzmanag = ZMPROT;  break;
  299.                 case 'q':
  300.                     Quiet=TRUE; Verbose=0; break;
  301.                 case 't':
  302.                     if (--argc < 1) {
  303.                         rusage();
  304.                         RETURN(1);
  305.                     }
  306.                     Rxtimeout = atoi(*++argv);
  307.                     if (Rxtimeout<10 || Rxtimeout>1000)
  308.                     {
  309.                         rusage();
  310.                         RETURN(1);
  311.                     }
  312.                     break;
  313.                 case 'v':
  314.                     ++Verbose; break;
  315.                 default:
  316.                     rusage();
  317.                     RETURN(1);
  318.                 }